using System;
using UnityEngine;
using XLua;

namespace Gameplay.PVE.UI
{
    public class PveJoyStick : MonoBehaviour
    {
        private Joystick joyStickController;
        public GameObject joyStick;
        private bool inited = false;
        private bool isActive = true;
        public void Init(Camera uiCamera = null)
        {
            inited = true;
            joyStickController = joyStick.GetComponent<Joystick>();
            joyStickController.Init(uiCamera);
        }

        public void SetOnDrag(Action<Vector2,float> action)
        {
            joyStickController.SetOnDrag(action);
        }

        public void SetOnDragLua(LuaFunction function)
        {
            joyStickController.SetOnDrag(function);
        }
        
        public void SetOnTouchUp(Action<Vector2> action)
        {
            joyStickController.SetOnTouchUp(action);
        }

        public void SetOnTouchStartLua(LuaFunction function)
        {
            joyStickController.SetOnTouchStart(function);
        }
        
        public void SetOnPress(Action action,float cd)
        {
            joyStickController.SetOnPress(action,cd);
        }
        
        public void SetOnTouchDown(Action<Vector2> action)
        {
            joyStickController.SetOnTouchDown(action);
        }

        public void UpdateJoystick()
        {
            //joyStickController.UpdateJoystick();
        }

        void Update()
        {
            if (!inited || !isActive)
            {
                return;
            }
            joyStickController.UpdateJoystick();
        }

        public void SetActive(bool isActive)
        {
            this.isActive = isActive;
            joyStickController.SetActive(this.isActive);
        }
    }
}